import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';

@Component({
    selector: 'kylin-modal',
    templateUrl: './kylin-modal.component.html',
    styleUrls: ['./kylin-modal.component.css']
})
export class KylinModalComponent implements OnInit {

    _isVisible = false;
    @Input() forms: any[];
    @Input() httpPath = '';
    @Input() title = '';
    @Input() httpAllowMethod = 'post';
    @Input() successMsg = '';
    @ViewChild('kylinForm') kylinForm;
    @Output() formSubmitSuccess: EventEmitter<any> = new EventEmitter<any>();

    constructor() {
    }

    ngOnInit() {
    }

    handleCancel(): void {
        this._isVisible = false;
    }

    onSubmit() {
        this.kylinForm.onSubmit()
            .then(res => {
                this._isVisible = false;
            })
            .catch(err => {
                // this._isVisible = false;
            });
    }

    showKylinModal = () => {
        this._isVisible = true;
    };

    successSubmit(event) {
        this.formSubmitSuccess.emit(event);
    }
}
